/**
 * Created by yuzhou on 2020/3/29.
 */
//获取
$(document).ready(function () {
    var app = new Vue({
        el: "#whole_box",
        data: {
            shopno_txt: "店铺号",
            tab1: "品牌介绍",
            tab2: "产品相册",
            tab3: "店铺实景",
            tel_txt: "电话",
            eamil_txt: "邮箱",
            url_txt: "网址",
            address_txt: "地址",
            phroductAlbum_txt: "产品展示",
            share_txt: "/xj/image/store/share.png",
            tel_txt: "电话",
            eamil_txt: "邮箱",
            url_txt: "网址",
            address_txt: "地址",
            phroductAlbum_txt:"产品展示",

            store_main_pic:"",
            store_logo: "",
            store_name_main: "",
            store_name: "",
            store_name_en: "",
            store_no: "",
            store_phone: "",
            store_email: "",
            store_website: "",
            store_address_main: "",
            store_address: "",
            store_address_en: "",
            store_name_main: "",
            store_name: "",
            store_name_en: "",

            pic_num: 0,

            pic_thumb1: "",
            pic_thumb2: "",
            pic_thumb3: "",
            pic_thumb4: "",
            pic_num:0,

            mainproductList:"",
            category_list:"",
            category_list_en:"",


            store_id:"",

            is_en:false,

            share_show:false,

            shopno_txt:"",
            mainproduct_txt:"",

            product_url:"",

            longitude:"",
            latitude:"",
            showcategory:false,
            mapUrl_gd:"",
            mapUrl_tx:"",
            mapUrl_bd:"",


            AutoNavi_txt:"",
            QQMap_txt:"",
            BaiduMap_txt:"",

            stores_live:""


        },
        mounted:function(){
            var self = this;
            var store_id = self.getQueryValue("id");
            self.store_id = store_id;
            self.product_url = "/page/redirectProduct?id="+self.store_id;

            $("#btnCE").click(function () {
                var img = document.getElementById("btnCE");
                console.log("Ssssss"+localStorage.getItem("language"));
                if(localStorage.getItem("language")=="en")
                {
                    img.src = "/xj/image/English.png";
                    localStorage.setItem("language", "cn");
                    self.changeToCn();
                    self.is_en = false;
                }
                else {
                    img.src = "/xj/image/chinese.png"
                    localStorage.setItem("language", "en");
                    self.changeToEn();
                    self.is_en = true;
                }
            });

            $.ajax({
                type:"GET",
                url:"/market/getStoreDetail",
                data: {
                    store_id: store_id
                },
                dataType:"json",
                success:function(res){
                    self.stores_live = res.stores_live;
                    self.store_main_pic = res.main_pic;
                    self.store_logo = res.logo;
                    self.store_no =  res.store_no;
                    self.store_phone =  res.phone;
                    self.store_email =  res.email;
                    self.store_website =  res.website;
                    self.store_address =  res.address;
                    self.store_address_en =  res.address_en;
                    self.category_list = res.category;
                    self.category_list_en = res.market_type;
                    if(res.product_show_pic[0].url !== ""){
                        self.pic_thumb1 = res.product_show_pic[0].url;
                    }

                    if(res.product_show_pic[1].url !== ""){
                        self.pic_thumb2 = res.product_show_pic[1].url;
                    }

                    if(res.product_show_pic[2].url !== ""){
                        self.pic_thumb3 = res.product_show_pic[2].url;
                    }

                    if(res.product_show_pic[3].url !== ""){
                        self.pic_thumb4 = res.product_show_pic[3].url;
                    }

                    self.pic_num = res.product_show_pic.length;
                    self.longitude = res.longitude;
                    self.latitude = res.latitude;

                    self.store_name =  res.store_name;
                    self.store_name_en =  res.store_name_en;

                    self.store_address_main = self.store_address;
                    self.store_name_main = self.store_name;
                    self.mainproductList = self.category_list;

                    if(localStorage.getItem("language")=="cn") {
                        self.changeToCn();
                        self.is_en = false;
                    }else{
                        self.changeToEn();
                        self.is_en = true;
                    }

                    $.ajax({
                        type:"GET",
                        url:"/market/getWpConig",
                        data: {
                            clientUrl:window.location.href.split("#")[0]
                        },
                        dataType:"json",
                        success:function(res){
                            console.log(JSON.stringify(res));
                            wx.config({
                                debug: false,
                                appId: res.appId, // 和获取Ticke的必须一样------必填，公众号的唯一标识
                                timestamp: res.timestamp, // 必填，生成签名的时间戳
                                nonceStr: res.nonceStr, // 必填，生成签名的随机串
                                signature: res.signature,// 必填，签名，见附录1
                                //需要分享的列表项:发送给朋友，分享到朋友圈，分享到QQ，分享到QQ空间
                                jsApiList: [
                                    'onMenuShareAppMessage', 'onMenuShareTimeline',
                                    'onMenuShareQQ', 'onMenuShareQZone'
                                ]
                            });
                            var share_config = {
                                "imgUrl": self.store_logo,
                                "desc": self.store_address,
                                "title": self.store_name,
                                "link": window.location.href,
                                "success": function () {
                                    //分享成功后的回调函数
                                    // alert('分享成功')
                                },
                                "cancel": function () {
                                    //用户取消分享执行的回调函数
                                    // alert('分享成功')
                                }
                            };

                            wx.ready(function () {
                                wx.onMenuShareAppMessage(share_config);//分享给好友
                                wx.onMenuShareTimeline(share_config);//分享到朋友圈
                            });

                        }
                    });

                    /*高德*/
                    self.mapUrl_gd = "http://uri.amap.com/marker?position="+self.longitude+","+self.latitude+"&name=" + "信基沙溪" + "&src=yellowpage&coordinate=gaode&callnative=1";

                    /*腾讯*/
                    self.mapUrl_tx = "http://apis.map.qq.com/uri/v1/marker?marker=coord:"+self.latitude+","+self.longitude+";title:" + "信基沙溪" + ";addr:" + "信基沙溪" + "&referer=yellowpage"
                    // console.log(mapUrl_tx);
                    // $(".mapBtn_t").attr("href", mapUrl_tx);
                    /*百度*/
                    self.mapUrl_bd = "http://api.map.baidu.com/marker?location="+self.latitude+","+self.longitude+"&title=" + "信基沙溪" + "&content=" + "信基沙溪" + "&output=html&src=yellowpage";
                    // console.log(mapUrl_bd);
                    // $(".mapBtn_b").attr("href", mapUrl_bd);
                }
            });

            toastr.options = {
                // toastr配置
                "closeButton": true, //是否显示关闭按钮
                "debug": false, //是否使用debug模式
                "progressBar": true, //是否显示进度条，当为false时候不显示；当为true时候，显示进度条，当进度条缩短到0时候，消息通知弹窗消失
                "positionClass": "toast-bottom-center",//显示的动画位置
                "showDuration": "400", //显示的动画时间
                "hideDuration": "1000", //消失的动画时间
                "timeOut": "7000", //展现时间
                "extendedTimeOut": "1000", //加长展示时间
                "showEasing": "swing", //显示时的动画缓冲方式
                "hideEasing": "linear", //消失时的动画缓冲方式
                "showMethod": "fadeIn", //显示时的动画方式
                "hideMethod": "fadeOut" //消失时的动画方式
            };




        },
        methods: {
            getQueryValue:function (a) {
                var query = decodeURI(window.location.search.substring(1));
                var vars = query.split("&");
                for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == a) { return pair[1]; }
                }
                return null;
            },

            getback:function () {
                window.history.back(-1);
            },

            changeToEn:function () {
                var self = this;
                self.store_address_main = self.store_address_en;
                self.store_name_main = self.store_name_en;
                self.mainproductList = self.category_list_en;

                self.share_txt = "/xj/image/store/share_en.png";
                self.tel_txt =  "Tel";
                self.eamil_txt =  "E-mail";
                self.url_txt = "URL";
                self.address_txt =  "Address";
                self.phroductAlbum_txt = "Product Album";
                self.shopno_txt =  "Shop No";
                self.tab1 =  "Brand Introduction";
                self.tab2 =  "Product Album";
                self.tab3 =  "Shop View";
                self.shopno_txt = "Shop No";
                self.mainproduct_txt = "Main Products";
                self.AutoNavi_txt = "Auto Navi";
                self.QQMap_txt = "QQ Map";
                self.BaiduMap_txt = "Baidu Map";
            },

            changeToCn:function () {
                var self = this;
                self.store_address_main = self.store_address;
                self.store_name_main = self.store_name;
                self.mainproductList = self.category_list;

                self.share_txt = "/xj/image/store/share.png";
                self.tel_txt =  "电话";
                self.eamil_txt =  "邮箱";
                self.url_txt = "网址";
                self.address_txt =  "地址";
                self.phroductAlbum_txt = "产品展示";
                self.shopno_txt =  "店铺号";

                self.tab1 =  "品牌介绍";
                self.tab2 =  "产品相册";
                self.tab3 =  "店铺实景";
                self.shopno_txt = "店铺号";
                self.mainproduct_txt = "主营";
                self.AutoNavi_txt = "高德地图";
                self.QQMap_txt = "腾讯地图";
                self.BaiduMap_txt = "百度地图";
            },

            call:function () {
                var self = this;
                window.location.href = "tel:"+self.store_phone;
            },

            introduceGo:function () {
                var self = this;
                window.location.href = "/page/redirectStoreIntroduce?id="+self.store_id
            },

            shareGo:function () {
                var self = this;
                if(self.share_show){
                    self.share_show = false;
                }else{
                    self.share_show = true;
                }


            },

            productGo:function () {
                var self = this;
                window.location.href = self.product_url;
            },

            getback:function () {
                window.history.back(-1);
            },


            storeVR:function () {
                var self = this;
                 if( self.stores_live == null ||  self.stores_live == ""){
                     toastr.info("尚未开通，敬请期待");
                 }else{
                     window.location.href = self.stores_live;
                 }

            },


            navigate:function () {
                var self = this;
                if (self.showcategory == true) {
                    self.showcategory = !self.showcategory;
                }else{
                    self.showcategory = !self.showcategory;
                }


            }




        },

    });
});